<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper" style="position: relative">
        <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="onQuery">
          <div class="mode_item">
            <a-form-model-item label="告警类型">
              <j-dict-select-tag v-model="form.alarmType" placeholder="请选择" dictCode="alarmType" />
            </a-form-model-item>
            <a-form-model-item label="告警目标">
              <a-input v-model="form.warningTarget" placeholder="请输入" />
            </a-form-model-item>
            <div>
              <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
                <a-button class="Indormation-list-CX" type="primary" @click="onQuery"> 查询 </a-button>
                <a-button class="Indormation-list-CX" style="margin-left: 10px" @click="onResetForm"> 重置 </a-button>
              </a-form-model-item>
            </div>
          </div>
          <div class="mode_item mode_item_none">
            <a-form-model-item label="时间范围" class="zdy-form-item-label">
              <a-radio-group buttonStyle="solid" v-model="form.flag">
                <a-radio-button v-for="(item, key) in options" :key="key" :value="item.value">
                  {{ item.text }}
                </a-radio-button>
              </a-radio-group>
              <a-range-picker
                v-if="form.flag === '5'"
                :allowClear="true"
                v-model="rangePickerTime"
                valueFormat="YYYY-MM-DD"
                format="YYYY-MM-DD"
                @change="rangePickerChange"
                style="margin-left: 10px"
              />
            </a-form-model-item>
          </div>
        </a-form-model>
      </div>
    </a-card>
    <a-card :bordered="false">
      <!-- 表格展示 -->
      <div class="table-page-content">
        <custom-table
          ref="table"
          rowKey="uuid"
          :showAlert="false"
          :showSelection="false"
          :loading="loading"
          :columns="columns"
          :dataSource="pageData"
          @change="onTableChange"
        >
          <template slot="alarmType" slot-scope="text">
            <span v-if="text == '漫出'" style="color: #F59A23;">{{ text }}</span>
            <span v-if="text == '漫入'" style="color: #D9001B;">{{ text }}</span>
          </template>
          <template slot="alarmPosition" slot-scope="text, record">
            <a-button @click="onTrack(record)" type="link" style="padding:0;">{{ text }}</a-button>
          </template>

          <!--操作-->
          <template slot="action" slot-scope="text, record">
            <a-button @click="handleDetails(record)" type="link" style="padding:0;">查看</a-button>
            <a-divider type="vertical" />
            <a-button
              v-if="record.ynDisposal == '1'"
              :disabled="true"
              @click="handleDispose(record)"
              type="link"
              style="padding:0;"
            >已处置</a-button
            >
            <a-button v-else @click="handleDispose(record)" type="link" style="padding:0;">未处置</a-button>
            <a-divider type="vertical" />
            <a-button @click="onAlarm(record)" type="link" style="padding:0;"> 一键报警</a-button>
          </template>
        </custom-table>
      </div>
      <!--弹窗区域 -->
      <DisposeModal :id="id" ref="disposeModalRef" @ok="modalFormOk" />
      <AlarmModal ref="alarmModal" />
    </a-card>
  </div>
</template>

<script>
import * as api from '@/api/xlgc/alarmCenter.js'
import CustomTable from '@/components/zxd/Table/CustomTable'
import DisposeModal from './components/disposeModal'
import AlarmModal from '@/views/xlgc/specialPerson/modules/alarmModal'
export default {
  components: {
    CustomTable,
    DisposeModal,
    AlarmModal
  },
  data() {
    return {
      labelCol: { span: 5 },
      wrapperCol: { span: 17 },
      rangePickerTime: [],
      loading: false,
      form: {
        flag: '1'
      },
      id: null,
      options: [
        { value: '0', text: '全部' },
        { value: '1', text: '近七天' },
        { value: '2', text: '近三天' },
        { value: '3', text: '昨天' },
        { value: '4', text: '今天' },
        { value: '5', text: '自定义' }
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 60,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` // 序号分页后连续
        },
        {
          title: '告警目标',
          dataIndex: 'name',
          width: 120,
          align: 'center'
        },
        {
          title: '联系方式',
          dataIndex: 'contactInformation',
          width: 110,
          align: 'center',
          scopedSlots: { customRender: 'contactInformation' }
        },
        {
          title: '籍贯',
          dataIndex: 'nativePlace',
          width: 100,
          align: 'center'
        },
        {
          title: '告警位置',
          dataIndex: 'alarmPosition',
          width: 115,
          align: 'center',
          scopedSlots: { customRender: 'alarmPosition' }
        },
        {
          title: '告警类型',
          dataIndex: 'alarmType',
          width: 115,
          align: 'center',
          scopedSlots: { customRender: 'alarmType' }
        },
        {
          title: '告警时间',
          dataIndex: 'alarmTime',
          width: 100,
          align: 'center'
        },
        {
          title: '操作',
          width: 180,
          align: 'center',
          dataIndex: 'action',
          // slots: { title: 'customIsAction' },
          scopedSlots: { customRender: 'action' }
        }
      ],
      pageFilter: {
        pageNo: 1,
        pageSize: 10
      },
      pageData: {}
    }
  },
  created() {
    this.onQuery()
  },
  methods: {
    onQuery() {
      this.pageFilter.pageNo = 1
      this.refreshTable()
    },
    onResetForm() {
      this.form = {
        flag: '1'
      }
      this.pageFilter.pageNo = 1
      this.pageFilter.pageSize = 10
      this.refreshTable()
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'index' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
      let form = Object.assign({}, this.form, this.pageFilter)
      this.loading = true
      api
        .personnelAlarmList(form)
        .then(res => {
          if (res.success) {
            this.pageData = res.result
            this.loading = false
          } else {
            this.loading = false
            this.$message.warn(res.message)
          }
        })
        .catch(e => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    // 弹窗成功接收
    modalFormOk(type) {
      this.onQuery()
    },
    onTrack(record) {
      let obj = {
        id: record.alarmInfoId,
        ynDisposal: record.ynDisposal,
        position: record.alarmPosition,
        longitude: record.longitude,
        latitude: record.latitude
      }
      this.$router.push({
        path: '/xlgc/alarmCenter/personAlarm/personTrack',
        query: {
          info: JSON.stringify(obj)
        }
      })
    },
    // 详情
    handleDetails(record) {
      let path = '/person/details'
        let query = { id: record.alarmInfoId }
      this.$router.push({ path: path, query })
    },
    onAlarm(record) {
      this.$refs.alarmModal.show(record.alarmInfoId)
    },
    handleDispose(record) {
      this.id = record.alarmInfoId
      this.$refs.disposeModalRef.show()
    },
    // 告警更新时间
    rangePickerChange(date) {
      this.$set(this.form, 'startTime', date[0])
      this.$set(this.form, 'endTime', date[1])
    }
  }
}
</script>
<style lang="less" scoped>
.mode_item {
  display: flex;
  // border-bottom: 1px #dadada dashed;
  > div {
    flex: 0 0 30%;
  }
  & > * {
    width: 100%;
    margin-bottom: 0;
    padding: 5px 0;
  }
  &.mode_item_none {
    > div {
      flex: inherit;
    }
  }
  .zdy-form-item-label {
    /deep/.ant-form-item-label {
      width: 6.2%;
    }
    &.xzqh-form-item-label {
      /deep/.ant-form-item-control-wrapper {
        .ant-form-item-children {
          display: -webkit-box;
        }
      }
      /deep/.area-select {
        // margin-top: 4px;
        line-height: 1;
      }
      /deep/.select-tag {
        width: 162px !important;
        margin-left: 10px;
        margin-top: 3px;
      }
      // /deep/.area-select .area-selected-trigger {
      //   line-height: 1.15;
      // }
      // /deep/.ant-select-lg .ant-select-selection--single{
      //   height: 34px;
      // }
      // /deep/.ant-select-lg .ant-select-selection__rendered {
      //   line-height: 34px;
      //   font-size: 14px;
      // }
    }
  }
}
.search-wrapper-btn {
  position: absolute;
  right: 0;
  top: 15px;
  z-index: 1;
}
/deep/.table-operator {
  display: flex;
  justify-content: space-between;
}
/deep/.table-custom-cols {
  top: -48px !important;
}
.custom-ewm {
  padding: 14px;
  background-color: #fff;
  border: 1px #ccc solid;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
}
/deep/.ant-dropdown-menu-item {
  text-align: center;
  border-bottom: 1px #f5f5f5 solid;
  &:last-child {
    border-bottom: 0;
  }
}
/deep/.anticon.anticon-down {
  font-size: 14px !important;
}

.table-page-content {
  /deep/.ant-table-thead > tr > th,
  /deep/.ant-table-tbody > tr > td {
    padding-left: 0;
    padding-right: 0;
  }
  /deep/.ant-table-thead > tr:first-child > th:first-child,
  /deep/.ant-table-tbody > tr > td:first-child {
    padding-left: 10px;
  }
  .text_color_1 {
    color: #bfbf00;
    padding-right: 6px;
  }
  .text_color_2 {
    color: #f59a23;
    padding-right: 6px;
  }
  .text_color_3 {
    color: #d9001b;
    padding-right: 6px;
  }
}
</style>
